package com.zmh.controller.wechat;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zmh.common.SignUtil;
import com.zmh.service.wechat.WeChatService;

/** 
 * @author zhoumh
 * @version 创建时间：2017年11月6日 下午4:40:43 
 * @Description 
*/
@Controller
@RequestMapping("/")
public class WeChatLoginController {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	@Autowired
	private WeChatService weChatService;
    /** 
     * 获取二维码图片与状态 
     */ 
	@RequestMapping("/getQrcode")  
    public void getQrcode(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String result = weChatService.getQrcode();
		logger.info("getQrcode : "+result);
		response.getWriter().write(result);
	}
    /** 
     * 验证二维码扫码状态，扫码成功后获取token完成登陆
     */ 
	@RequestMapping("/checkQrcode")  
    public void checkQrcode(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String result = weChatService.checkQrcode();
		logger.info("checkQrcode : "+result);
		response.getWriter().write(result);
	}
	/**
	 * 验证微信公众号是否在登陆状态
	 */
	@RequestMapping("/checkLogin")  
	public void checkLogin(HttpServletRequest request, HttpServletResponse response) throws IOException{
		boolean result = weChatService.checkLogin();
		logger.info("checkLogin : "+result);
		response.getWriter().write(String.valueOf(result));
	}
	

}
